﻿using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Project1.Application
{
    /// <summary>
    /// 系统服务接口
    /// </summary>
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _systemService;

        private readonly IHttpContextAccessor _httpContextAccessor;

        public SystemAppService(ISystemService systemService, IHttpContextAccessor httpContextAccessor)
        {
            _systemService = systemService;
            _httpContextAccessor = httpContextAccessor;
        }

        [AllowAnonymous]
        public string GetToken()
        {
            var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>()
            {
                { "UserId", "1"},  // 存储Id
            }, expiredTime: 60 * 24 * 365 * 99);        // 99年

            var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 60 * 24 * 365 * 99);        // 99年

            _httpContextAccessor.HttpContext.Response.Headers["access-token"] = accessToken;
            _httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;

            return "ok";
        }

        /// <summary>
        /// 获取系统描述
        /// </summary>
        /// <returns></returns>
        [Authorize]
        public string GetDescription()
        {
            return _systemService.GetDescription();
        }
    }
}
